// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
const apiPrefix = '/web';

/** 2、新增设备 POST /device/manager/add */
export async function deviceManagerControllerAdd(
  body: API.DeviceManagerReq,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultVoid>(`${apiPrefix}/device/manager/add`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 5、批量删除设备信息 DELETE /device/manager/batchDelete */
export async function deviceManagerControllerBatchDelete(
  body: number[],
  options?: { [key: string]: any },
) {
  return request<API.ApiResultVoid>(`${apiPrefix}/device/manager/batchDelete`, {
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 批量启用/禁用设备 POST /device/manager/batchEnOrDisableDevices */
export async function deviceManagerControllerBatchEnOrDisableDevices(
  body: API.DeviceStatusReq,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultVoid>(`${apiPrefix}/device/manager/batchEnOrDisableDevices`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 设备详情 GET /device/manager/detail/${param0} */
export async function deviceManagerControllerDeviceDetail(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.deviceManagerControllerDeviceDetailParams,
  options?: { [key: string]: any },
) {
  const { id: param0, ...queryParams } = params;
  return request<API.ApiResultDeviceManagerDTO>(`${apiPrefix}/device/manager/detail/${param0}`, {
    method: 'GET',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 6、获取设备类型列表 GET /device/manager/deviceTypes */
export async function deviceManagerControllerGetDeviceTypeList(options?: { [key: string]: any }) {
  return request<API.ApiResultListDeviceTypeVO>(`${apiPrefix}/device/manager/deviceTypes`, {
    method: 'GET',
    ...(options || {}),
  });
}

/** 4、编辑设备信息 PUT /device/manager/edit */
export async function deviceManagerControllerEdit(
  body: API.DeviceManagerReq,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultVoid>(`${apiPrefix}/device/manager/edit`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 7、根据设备型号获取设备信息 GET /device/manager/getDeviceDetailByModel */
export async function deviceManagerControllerGetDeviceDetailByModel(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.deviceManagerControllerGetDeviceDetailByModelParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultDeviceManagerDTO>(
    `${apiPrefix}/device/manager/getDeviceDetailByModel`,
    {
      method: 'GET',
      params: {
        ...params,
      },
      ...(options || {}),
    },
  );
}

/** 6、获取设备型号列表 GET /device/manager/getDeviceModelList/${param0} */
export async function deviceManagerControllerGetDeviceModelList(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.deviceManagerControllerGetDeviceModelListParams,
  options?: { [key: string]: any },
) {
  const { deviceType: param0, ...queryParams } = params;
  return request<API.ApiResultListDeviceModelVO>(
    `${apiPrefix}/device/manager/getDeviceModelList/${param0}`,
    {
      method: 'GET',
      params: { ...queryParams },
      ...(options || {}),
    },
  );
}

/** 1、分页列表 GET /device/manager/list */
export async function deviceManagerControllerDeviceList(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.deviceManagerControllerDeviceListParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultPaginationDeviceManagerDTO>(`${apiPrefix}/device/manager/list`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 3、设备图片上传 POST /device/manager/uploadPic */
export async function deviceManagerControllerUploadPic(
  body: {},
  attr?: File,
  options?: { [key: string]: any },
) {
  const formData = new FormData();

  if (attr) {
    formData.append('attr', attr);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.ApiResultObject>(`${apiPrefix}/device/manager/uploadPic`, {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}
